package com.bjqg.bjqg01.bjqg.activity.address.adapter;


import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bjqg.bjqg01.bjqg.R;
import com.bjqg.bjqg01.bjqg.activity.longrange.adapter.MutipleListAdapter;
import com.bjqg.bjqg01.bjqg.activity.longrange.bean.AddressBean;
import com.bjqg.bjqg01.bjqg.activity.seekprice.adapter.ContentAdapter;
import com.bjqg.bjqg01.bjqg.activity.seekprice.bean.ContentBean;
import com.zhy.autolayout.AutoLinearLayout;
import com.zhy.autolayout.AutoRelativeLayout;

import java.util.List;

/**
 * Created by bjqg01 on 2018/8/31.
 */

public class AddressAdapter extends RecyclerView.Adapter<AddressAdapter.MyViewHolder> {

    List<AddressBean> list;
    Context context;


    private onItemClickListener onItemClickListener;

    public interface onItemClickListener {
        void onItem(int position);
    }

    public void setOnItemClickListener(onItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public AddressAdapter(List<AddressBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(context).inflate(R.layout.item_address, parent, false);
        return new AddressAdapter.MyViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.name.setText(list.get(position).getName());

        holder.allfather.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListener != null) {
                    onItemClickListener.onItem(position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {

        public TextView name;
        public TextView phone;
        public TextView address;
        public TextView title;
        public ImageView ivchange;
        public AutoRelativeLayout allfather;

        public MyViewHolder(View itemView) {
            super(itemView);
            name = (TextView) itemView.findViewById(R.id.tv_name);
            phone = (TextView) itemView.findViewById(R.id.tv_phone);
            address = (TextView) itemView.findViewById(R.id.tv_address);
            title = (TextView) itemView.findViewById(R.id.tv_title);
            ivchange = (ImageView) itemView.findViewById(R.id.iv_change);
            allfather = (AutoRelativeLayout) itemView.findViewById(R.id.rl_father);
        }
    }
}
